package session.stateless;

import entity.Stakeholder;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Stateless
public class StakeholderSession implements StakeholderSessionLocal {

    @PersistenceContext
    private EntityManager em; 

    public Stakeholder getStakeholder(String username) {
        Query query = em.createQuery("SELECT s FROM Stakeholder s WHERE s.username = :UserName");
        query.setParameter("UserName", username); 
        
        Stakeholder stakeholder = null; 
        
        try{
            System.out.println("Can leh..");
            stakeholder = (Stakeholder)query.getSingleResult(); 
            System.out.println("Eh sai ..");
        }
        catch(NoResultException ex){
            ex.printStackTrace();
        }
                
        return stakeholder; 
    }

    
}
